import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-01-23
 * Time: 19:34
 */
class MinStack {
    Stack<Integer> stack;
    Stack<Integer> minstack;
    public MinStack() {
        stack = new Stack<>();
        minstack = new Stack<>();
    }

    public void push(int val) {
        stack.push(val);
        if(minstack.empty()) {
            minstack.push(val);
        }else {
            if(val <= minstack.peek()) {
                minstack.push(val);
            }
        }
    }

    public void pop() {
        Integer val = stack.pop();
        if(val.equals(minstack.peek())) {
            minstack.pop();
        }
    }

    public int top() {
        if(stack.empty()) {
            return -1;
        }
        return stack.peek();
    }

    public int getMin() {
        return minstack.peek();
    }

    public static void main(String[] args) {
        MinStack stack1 = new MinStack();
        stack1.push(1);
        System.out.println(stack1.top());
    }
}

